{layout name="common/layout" /}
 
 <style>
	.setting_all{
		font-size: 15px;
		height: 35px;
		width: 100px;
		text-align: center;
		line-height: 30px !important;
		color: #fff;
		border-radius: 3px;
		cursor: pointer;
		background-color: #2196f3;
		margin-left: 5px;
	 }
 </style>
<style>
    .table tr td:nth-of-type(0){
        white-space: nowrap;
    }
    .table tr td:nth-of-type(1){
        white-space: nowrap;
    }
    .table tr td:nth-of-type(2){
        word-wrap:break-word;
    }
    .table tr td:nth-of-type(3){
        word-wrap:break-word;
    }
    .table tr td:nth-of-type(4){
        word-wrap:break-word;
    }
    .table tr td:nth-of-type(5){
        word-wrap:break-word;
    }
    .table tr td:nth-of-type(6){
        word-wrap:break-word;
    }
    .table tr td:nth-of-type(7){
        word-wrap:break-word;
    }

</style>
<div class="dislpayArrow hidden-xs"><a class="pngfix" href="javascript:void(0);" onClick="displaynavbar(this)"></a></div>


<div class="Hui-article-box">
	<div class="Hui-article" style="top:0px;overflow-y: hidden;">
		<!-- 图书列表主体页面 -->
			<h3 class="showlist_title">所有图书</h3>

			<div class="showlist_form"> 
				<form action="{:url('book/listBook')}" method="get" style="border:0;">
					<?php $keyword = input('param.keyword'); ?>
					<span >图书名称</span><input type="text" value="{$keyword}" class="input-text" style="width:250px" placeholder="输入图书关键词" id="" name="keyword">
					
					<!-- 时间选择器 -->
					<div class="showlist_timeselect" >
					<?php 
						$begintime = input('param.begintime');
						$endtime = input('param.endtime');
						$type = input('param.type');
					?>
					录入时间
					<input id="start" value="{$begintime}"  name="begintime" class="input-text radius size-M" type="text" onClick="WdatePicker()"/>
					<b style="color: #000;font-weight: normal;margin-left: 5px;">至</b>
					<input id="end" value="{$endtime}" name="endtime"  class="input-text radius size-M input-boxs" type="text" onClick="WdatePicker()"/>
				</div>
					<button type="submit" class="btn btn-success radius" id="btn_sub" name=""> 搜索</button>
                    <span class="lose_rate" style="font-size: 20px;margin-left: 80px;margin-top: 10px;">缺货率</span>
					<!--<a class="btn setting_all" href="/merchant/bookattr/show">批量设置</a>-->
					<input id="type" value="{$type}" style="width:140px;" name="type"  type="hidden"/>
				</form>
			</div>
			<div>
				<div id="tab_demo" class="HuiTab">
				  <div class="tabBar clearfix showlist_tabBar"><span >全部图书</span><span>保存的图书</span><span>已上架图书</span><span>已下架的图书</span></div>
				  <?php if ($type == 0) { ?>
				  <div class="tabCon">
					<table class="table table-border table-bg  table-bordered" id="list_book">
 						<tr class="text-c first-tr">
                            <td>详情图</td>
                            <td>主图</td>
                            <td>折扣价</td>
                            <td>图书名称</td>
                            <td>图书系列</td>
                            <td>库存</td>

                            <!--<td>作者</td>-->
                            <!--<td>出版社</td>-->
                            <td>年龄</td>
                            <!--<td>摘要</td>-->
                            <!--<td>时间</td>-->
                            <td>操作</td>
                         </tr>
                         {foreach($data as $k => $v)}
                         <tr style="height: 80px;" class="text-c" id="{$v['id']}">
                            <td style="height: 200px;width: 200px;">
                            <?php
                            if(empty($v['img_main'])){
                                echo ' <img style="height: 200px;width: 200px;" src="" alt="" >';
                                }else{
                                    $newUrl = explode(',',$v['img_main'])[0];
                                    echo ' <img style="height: 200px;width: 200px;" src="'.$newUrl.'" alt="" >';
                                }
                            ?>
                            </td>
                            <td><img style="height: 200px;width: 200px;" src="{$v['img_medium']}" alt="" ></td>
                            <td>{$v['price']*$v['discount']/100}</td>
 							<td>{$v['title']}</td>
                            <td>{$v['series']}</td>
                            <td>{$v['stock']}</td>

                             <!--<td>{$v['author']}</td>-->
                             <!--<td>{$v['publisher']}</td>-->
                            <td>{$v['min_age'].'-'.$v['max_age']}</td>
                            <!--<td style="width: 680px;">{$v['summary']}</td>-->
 							<!--<td>{$v['create_time']}</td>-->
 							<td>
                                <a href="{:url('book/updateBook', ['bookid'=>$v['id'],'page'=>$page,'type'=>$type,'keyword'=>$keyword,'begintime'=>$begintime,'endtime'=>$endtime])}" class="aa">修改</a>
							<?php
							if($v["status"]!=9){
								if($v["status"]==3 || $v["status"]==1)
								{
								echo '<a href="javascript:void(0);" onclick="puton('.$v['id'].');" class="aa">上架</a>';
								}else
								{
								echo '<a href="javascript:void(0);" onclick="putdown('.$v['id'].');" class="aa">下架</a>';
								}
							}
							?>
							<a href="javascript:void(0);" onclick="del({$v['id']});" class="aa">删除</a>
                            <a href="javascript:void(0);" class="rent_item aa" onclick="rent({$v['id']});">租赁清单</a></td>
  						</tr>
  						{/foreach}
					</table>
				<div class="cl">
						{$data->render()}
				</div>
				<?php } elseif ($type == 2) { ?>
				<div class="tabCon"></div>
				<div class="tabCon"></div>
				<div class="tabCon">
					<table class="table table-border table-bg  table-bordered" >
 						<tr class="text-c first-tr">
                            <!--<td>主图</td>-->
                            <td>图书名称</td>
                            <td>图书系列</td>
                            <td>上架时间</td>
                            <td>操作</td>
                         </tr>
                         {foreach($data as $k1 => $v1)}

                         <tr style="height: 14px;" class="text-c">
                           <!--<td><img style="height: 14px;" src="{$v1['img_medium']}" alt="" ></td>-->
                            <td>{$v1['title']}</td>
                            <td>{$v1['series']}</td>
                            <td>{$v1['create_time']}</td>
                            <td>
                            <a href="{:url('book/updateBook', ['bookid'=>$v1['id'],'page'=>$page,'type'=>$type,'keyword'=>$keyword,'begintime'=>$begintime,'endtime'=>$endtime])}" class="aa">修改</a>
                            <a href="javascript:void(0);" onclick="putdown({$v1['id']});" class="aa">下架</a>
                           <a href="javascript:void(0);" onclick="del({$v1['id']});" class="aa">删除</a>
                           <a href="javascript:void(0);" class="rent_item aa" onclick="rent({$v1['id']});">租赁清单</a>
                           </td>
                         </tr>
                         {/foreach}
                   </table>
                  <div class="cl">
                       {$data->render()}
                   </div>
               </div>
               <?php } else if ($type == 1) {?>
               <div class="tabCon"></div>
               <div class="tabCon">
                   <table class="table table-border table-bg  table-bordered" >
                        <tr class="text-c first-tr">
                            <!--<td>主图</td>-->
                            <td>图书名称</td>
                            <td>图书系列</td>
                            <td>保存时间</td>
                            <td>操作</td>
                         </tr>
                         {foreach($data as $k2 => $v2)}
                         <tr style="height: 14px;" class="text-c">
							 <!--<td><img style="height: 14px;" src="{$v2['img_medium']}" alt="" >-->
                             <td>{$v2['title']}</td>
                             <td>{$v2['series']}</td>
                             <td>{$v2['create_time']}</td>
                             <td>
                            <a href="{:url('book/updateBook', ['bookid'=>$v2['id'],'page'=>$page,'type'=>$type,'keyword'=>$keyword,'begintime'=>$begintime,'endtime'=>$endtime])}" class="aa">修改</a>
                            <a href="javascript:void(0);" onclick="puton({$v2['id']});" class="aa">上架</a>
                            <a href="javascript:void(0);" onclick="del({$v2['id']});" class="aa">删除</a>
                            <a href="javascript:void(0);" class="rent_item aa" onclick="rent({$v2['id']});">租赁清单</a>
                            </td>
                          </tr>
                          {/foreach}
                    </table>
                    <div class="cl">
                        {$data->render()}
                    </div>
                </div>
                  <?php } else if ($type == 3) {?>
                <div class="tabCon"></div>
                <div class="tabCon"></div>
                <div class="tabCon"></div>
                <div class="tabCon">
                    <table class="table table-border table-bg  table-bordered" >
                         <tr class="text-c first-tr">
                             <!--<td>主图</td>-->
                             <td>图书名称</td>
                             <td>图书系列</td>
                             <td>下架时间</td>
                             <td>操作</td>
                          </tr>
                          {foreach($data as $k3 => $v3)}
                          <tr style="height: 14px;" class="text-c">
							  <!--<td><img style="height: 14px;" src="{$v3['img_medium']}" alt="" ></td>-->
                              <td>{$v3['title']}</td>
                              <td>{$v3['series']}</td>
                              <td>{$v3['create_time']}</td>
                              <td>
                             <a href="{:url('book/updateBook', ['bookid'=>$v3['id'],'page'=>$page,'type'=>$type,'keyword'=>$keyword,'begintime'=>$begintime,'endtime'=>$endtime])}" class="aa">修改</a>
                             <a href="javascript:void(0);" onclick="puton({$v3['id']});" class="aa">上架</a>
                             <a href="javascript:void(0);" onclick="del({$v3['id']});" class="aa">删除</a>
                             <a href="javascript:void(0);" class="rent_item aa" onclick="rent({$v3['id']});">租赁清单</a>
                             </td>
                           </tr>
                           {/foreach}
                     </table>
                     <div class="cl">
                         {$data->render()}
                     </div>
                 </div>
                 <?php } ?>
             </div>
         </div>
                <div id="rent-demo" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
                    <div class="modal-dialog" style="margin:30px 400px;">
                        <div class="modal-content radius" style="width: 700px;margin-left: 300px;">
                            <div class="modal-header">
                                <h3 class="modal-title" style="text-align: center;">图书租赁清单</h3>
                                <a class="close" data-dismiss="modal" aria-hidden="true" href="javascript:void();">×</a>
                            </div>
                            <div class="modal-body">
                                <img class="loading" src="__MERCHANT_STATIC__/style/images/loading.gif" style="position: absolute;float: left;margin: 250px 550px;display:none;"/>
                                <div id="print_area">
                                    <div style="text-align: center;position: relative;font-size: 25px;margin: 20px 0;">
                                        <span class="stock_show">总库存X本，剩余库存X本</span>
                                    </div>
                                    <table class="rent_tab" style="border: 1px solid black;border-collapse:collapse;text-align: center;">
                                        <thead>
                                        <td style="border: 1px solid black;">订单</td>
                                        <td style="border: 1px solid black;">起租日期</td>
                                        <td style="border: 1px solid black;">归还日期</td>
                                        <td style="border: 1px solid black;">用户</td>
                                        <td style="border: 1px solid black;">收货人信息</td>
                                        <td style="border: 1px solid black;">书本数</td>
                                        <td style="border: 1px solid black;">状态</td>
                                        </thead>
                                        <tbody class="dorder_list">

                                        </tbody>
                                    </table>
                                </div>
                            </div>
                            <div class="modal-footer">
                                <span class="page_bat" style="margin-right: 20px;"></span>
                                <!--<span class="btn previousPage">上一页</span>-->
                                <!--<span class="btn nextPage">下一页</span>-->
                                <span class="btn close_btn">关闭</span>
                            </div>
                        </div>
                    </div>
                </div>
     </div>
  </div>
  <script>
     $(function(){
         $.Huitab("#tab_demo .tabBar span","#tab_demo .tabCon","current","click","{$type}")
         $.post("{:url('book/getLoseRate')}",{},function(data) {
             if(data.status == 1){
                 $(".lose_rate").empty();
                 $(".lose_rate").html("缺货率："+data.lose_rate+"%");
             }else{
                 layer.msg("缺货率无法获取");
             }
         },'json');
     });
     var GG =
     {
         "kk":function(mm)
         {
            var ym=mm;
         }
     };
     var stime_id = 0;
     function scrollBook(){
         var point = "{$point}";
         if(parseInt(point) > 0){
             $(".Hui-article-box").animate({
                 scrollTop:$("#"+point).offset().top - 120
             },100);
         }
         clearInterval(stime_id);
     }
     stime_id = setInterval(scrollBook,100);


     /*新增页面跳转*/
     $("ul.pagination").append("<li style='width:100px;padding-left: 10px;margin-right: 20px;'><div style='height: 24px;width: 100px;position: relative;display: inline-block;'>"+
     "<input type='text' value='{$page}' class='page_jump_num' style='text-align:center;border: 1px solid black;width:50px;display: inline-block;position: relative;float: left;margin:2px 0 0 -5px;' />"+
     "<a class='page_jump' style='display: inline-block;position: relative;float: right;background-color:#2196f3;color:#FFF;'>跳转</a>"+
     "<div style='clear: both;'></div></div></li>");

     $(".page_jump").click(function () {
         var page = $(".page_jump_num").val();
         window.location.href="{:url('book/listbook')}?page="+page+"&type="+"{$type}"+"&keyword="+"{$keyword}"+"&begintime="+"{$begintime}"+"&endtime="+"{$endtime}";
     });

     $(".paginate").initPage(71,1,GG.kk);

      $(function(){
         // 为span元素绑定click事件
         $('#tab_demo .tabBar span').bind("click",function(event) {
             // $('#type').val(1);
             if($(this).html()=="全部图书"){
                 $('#type').val(0);
                 $('#type1').val(0);
             }
             if($(this).html()=="已上架图书"){
                 $('#type').val(2);
                 $('#type1').val(2);
             }
             if($(this).html()=="保存的图书"){
                 $('#type').val(1);
                 $('#type1').val(1);
             }
             if($(this).html()=="已下架的图书"){
                 $('#type').val(3);
                 $('#type1').val(3);
             }
             $("#btn_sub").click();
         });

         function flash(){
             window.location.reload();
         }
         //setInterval(flash,8000);
     });
      //删除
     function del(id)
     {
         layer.msg('你确定要删除吗？', {
             time: 0,
             btn: ['确定', '取消'],
             area: ['250px', '120px'],
             btnAlign: 'c',
             yes: function(index){
                 layer.close(index);
                 $.ajax({
                     type : 'post',
                     url : "<?php echo url('book/deleteBook', '', false); ?>/bookid/" + id,
                     dataType : 'json',
                     success : function(data){
                         if(data.status == 1)
                         {
                             layer.msg(data.msg,
                             {
                                 offset: 't',
                                 anim: 5,
                                 success : function()
                                 {
                                     location.reload();
                                 }
                             });
                         }else{}
                     }
                 });
             }
         });
     }
     //下架
     function putdown(id)
     {
         $.ajax({
             type : 'post',
             url : "<?php echo url('book/bookPutDown', '', false); ?>/bookid/" + id,
             dataType : 'json',
             success : function(data){
                 if(data.status == 1)
                 {
                     layer.msg(data.msg, {
                         offset: 't',
                         anim: 5,
                         success : function(){
                             location.reload();
                         }
                     });
                 }

             }
         });
//         layer.msg('你确定要下架吗？', {
//             time: 0,
//             btn: ['确定', '取消'],
//             area: ['250px', '120px'],
//             btnAlign: 'c',
//             yes: function(index){
//                 layer.close(index);
//             }
//         });
     }
     //上架
     function puton(id)
     {
         $.ajax({
             type : 'post',
             url : "<?php echo url('book/bookPutOn', '', false); ?>/bookid/" + id,
             dataType : 'json',
             success : function(data){
                 if(data.status == 1)
                 {
                     layer.msg(data.msg, {
                         offset: 't',
                         anim: 5,
                         success : function(){
                             location.reload();
                         }
                     });
                 }
             }
         });
//         layer.msg('你确定要上架吗？', {
//             time: 0,
//             btn: ['确定', '取消'],
//             area: ['250px', '120px'],
//             btnAlign: 'c',
//             yes: function(index){
//                 layer.close(index);
//             }
//         });
     }

     function rent(id)
     {
         $("#rent-demo").modal("show");
         $(".loading").show();
         $.post("{:url('book/getBookRentItem')}",{book_id:id},function(data) {
             if(data.status == 1){
                 $(".stock_show").empty();
                 $(".stock_show").html("总库存"+data.data.stock_info.stock+"本，剩余库存"+data.data.stock_info.surplus_stock+"本");
                 var dorder = $('.dorder_list');
                 dorder.empty();
                 for(var i=0;i<data.data.rent_list.length;i++){
                     dorder.append("<tr><td style='border: 1px black solid'>"+data.data.rent_list[i].order_sn+"</td><td style='border: 1px black solid'>"+data.data.rent_list[i].start_time+"</td><td style='border: 1px black solid'>"+data.data.rent_list[i].end_time+"</td><td style='border: 1px black solid'>"+data.data.rent_list[i].user_phone+"</td><td style='border: 1px black solid'>"+data.data.rent_list[i].name+"--"+data.data.rent_list[i].mobile+"</td><td style='border: 1px black solid'>"+data.data.rent_list[i].book_num+"</td><td style='border: 1px black solid'>"+data.data.rent_list[i].status+"</td></tr>");
                 }
                 $(".loading").hide();
             }else{
                 layer.msg(data.msg);
                 $(".loading").hide();
                 $("#rent-demo").modal("hide");
             }
         },'json');
     }

     $(".close_btn").click(function () {
         $("#rent-demo").modal("hide");
     })

  </script>